package com.example.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.example.domain.Lines;
import com.example.service.LinesService;

@Controller
public class LinesController {

	@Autowired
	private LinesService linesService;
	
	@RequestMapping("/api/{lineId}")
	public String getLinesByLineId(HttpServletRequest request, @PathVariable(value="lineId") Integer lineId){
		request.setAttribute("line", linesService.findByLineId(lineId));
		return "metro/lines";
	}
	
	@RequestMapping("/api/lines")
	public String findAllLines(Model model){
		List<Lines> list = linesService.findAllLines();
		model.addAttribute("lineList", list);
		return "metro/lines";
	}
	
	@RequestMapping(value="/api/linesInfo", method=RequestMethod.GET)
	@ResponseBody
	public List<Lines> findAllLinesInfo(){
		return linesService.findAllLines();
//		return linesService.findAllLines();
	}
	
	@RequestMapping("/api/getLineInfo")
	public void insertData(){
//		linesService.setLinesInfo();
	}
}
